﻿<UserControl x:Class="WordsAsap.Pages.Home"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WordsAsap.Pages" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:controls="clr-namespace:FeserWard.Controls;assembly=Intellibox"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" 
             Loaded="Home_OnLoaded"
             >
    <UserControl.DataContext>
        <local:HomeViewModel/>
    </UserControl.DataContext>
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="VisibilityConverter" />
    </UserControl.Resources>
    
    <UserControl.InputBindings>        
            <KeyBinding Modifiers="Control"
                    Key="S"
                    Command="{Binding SaveWordCommand}"/>           
    </UserControl.InputBindings>

    <Grid   Style="{StaticResource ContentRoot}" >
        <ScrollViewer>
            <Grid Name="gr1" KeyboardNavigation.TabNavigation="Cycle" >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="5" />
                    <ColumnDefinition Width="95" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="120" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="10" />
                    <RowDefinition Height="26" />
                    <RowDefinition Height="Auto" MinHeight="25" />
                    <RowDefinition Height="30" />
                    <RowDefinition Height="45" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                
                    <TextBlock Grid.Row="1" Grid.Column="1" 
                               Margin ="2"   HorizontalAlignment="Right" VerticalAlignment="Center" TextAlignment="Right"
                               Text="New word " 
                               />

                <mui:ModernButton Grid.Row="1" Grid.Column="3" Padding="1" Margin="1" Content="[clear all]" 
                                                  Command="{Binding  NewWordCommand}"
                                                  IconData="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z "
                                  TabIndex="4" />

                <controls:Intellibox  Name="wordInput"
                                      Grid.Row="1"
                                      Grid.Column="2"
                                      Margin="6,2,1,1"
                                      TabIndex="0"
                                      Focusable="True"
                                      ResultsHeight="180"
                                      ResultsWidth="{Binding ElementName=wordInput,Path=ActualWidth}"
                                      ExplicitlyIncludeColumns="True"
                                      DisplayedValueBinding="{Binding Value}"
                                      SelectedItem="{Binding SelectedWord}"
                                      SelectedValueBinding="{Binding Value}"
                                      SelectedValue="{Binding NewWord}"
                                      DataProvider="{Binding Path=LinqToEntitiesProvider}"
                                      VerticalAlignment="Top"
                                      HorizontalContentAlignment="Stretch">
                    <controls:Intellibox.Resources>
                        <Style TargetType="ListView">
                            <Setter Property="Background" Value="{StaticResource ModernButtonIconBackgroundPressed}" />
                            <Setter Property="ItemContainerStyle">
                                <Setter.Value>
                                    <Style TargetType="ListViewItem">
                                        <Setter Property="Background" Value="Transparent" />
                                    </Style>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </controls:Intellibox.Resources>
                    <controls:Intellibox.Columns>
                        <controls:IntelliboxColumn DisplayMemberBinding="{Binding Value}" 
                                                   Header="Word" />
                    </controls:Intellibox.Columns>
                </controls:Intellibox>

                <TextBlock  Grid.Row="2" Grid.Column="1"
                            Margin="2,4,4,2" VerticalAlignment="Top" HorizontalAlignment="Right" TextAlignment="Right" Padding="0,0,2,0"                            
                            Text="Translations "   
                             />
                <ListView  Grid.Row="2" Grid.Column="2" Grid.ColumnSpan="2" 
                           HorizontalAlignment="Stretch"
                           HorizontalContentAlignment="Stretch"
                           ItemsSource="{Binding Translations}" 
                           x:Name="lstv"
                           KeyboardNavigation.TabNavigation="Local"
                           IsTabStop="False"
                           TabIndex="1">
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}">
                         <Setter Property="IsTabStop" Value="False" />
                        </Style>
                    </ListView.ItemContainerStyle>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition  />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <TextBox Text="{Binding Translation}" 
                                         Margin="2"
                                         TextAlignment="Left"
                                         TabIndex="1"
                                         >
                                    <TextBox.InputBindings>
                                        <KeyBinding Key="Enter" Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, 
                                            Path=DataContext.AddTranslationCommand}"/>
                                    </TextBox.InputBindings>
                                </TextBox>

                                <mui:ModernButton Grid.Column="1" Padding="1" Margin="1" 
                                                  IsTabStop="False"
                                                  Content="[remove]" 
                                                  Command="{Binding ElementName=lstv, Path=DataContext.RemoveTranslationCommand}"
                                                          CommandParameter="{Binding}"
                                                  IconData="F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z " 
                                                   />
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ListView>


                <mui:ModernButton  Grid.Row="3" Grid.Column="2" 
                        VerticalAlignment="Top"  HorizontalAlignment="Left" 
                                   Padding="1" Margin="1" 
                                   Content="add translation  [Enter]" 
                                      Command="{Binding AddTranslationCommand}"
                                      IconData="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z" 
                                   TabIndex="2"
                                      />

                <mui:ModernButton  Grid.Row="4" Grid.Column="1"  Grid.ColumnSpan="2"
                        Padding="1" Margin="1" VerticalAlignment="Top" HorizontalAlignment="Center"
                                      Content="save word [ctrl+s]" 
                                      Command="{Binding SaveWordCommand}"
                                      IconData="F1 M 20.5833,20.5833L 55.4167,20.5833L 55.4167,55.4167L 45.9167,55.4167L 45.9167,44.3333L 30.0833,44.3333L 30.0833,55.4167L 20.5833,55.4167L 20.5833,20.5833 Z M 33.25,55.4167L 33.25,50.6667L 39.5833,50.6667L 39.5833,55.4167L 33.25,55.4167 Z M 26.9167,23.75L 26.9167,33.25L 49.0833,33.25L 49.0833,23.75L 26.9167,23.75 Z" HorizontalContentAlignment="Right" 
                                      TabIndex="3"
                                   />
            </Grid>
        </ScrollViewer>
    </Grid>
</UserControl>
